import { forBindEventThis } from '../../../../../global/direct/Func';
import { event_check_operate } from '../../../../../global/element/Event/Func/event_check/Classes/cla_event_check_operate';
import { check_cur_node_selectable } from '../Func/check_cur_node_selectable';
import {
  check_cur_node_is_selected,
  select_node_dataMana,
} from './cla_select_node_dataMana';

const select_node_operateTag = 'select_node_operate';

const event_check_func = new event_check_operate();

export class select_node_operate extends select_node_dataMana {
  get [Symbol.toStringTag]() {
    return select_node_operateTag;
  }

  constructor(props) {
    super(props);

    forBindEventThis(this);

    this.eventM.addEventListen(
      this.dom_select_node,
      'click',
      this.eventBind.select_node_click
    );

    this.eventM.addEventListen(
      this.dom_focusDisplay_container,
      'click',
      this.eventBind.content_chi_selectable_click
    );

    this.eventM.addEventListen(
      this.dom_focusDisplay,
      'click',
      this.eventBind.focusDisplay_white_space_self_click
    );
  }

  /**
   * 选中 或 取消 元素
   * @param {MouseEvent} event
   */
  content_chi_selectable_click(event) {
    let cur_node = event.target;

    // 判定 内容元素 是否可以 被选取
    if (!check_cur_node_selectable(cur_node)) {
      return;
    }

    /**
     * 逻辑 修订
     */
    if (check_cur_node_is_selected(cur_node)) {
      // 当 当前元素 已经被选中时 取消选中
      this.remove_cur_node_selected(cur_node);
    } else {
      // 当前 元素 未被选中时 设定选中 当前元素
      this.set_cur_node_selected(cur_node);
    }
  }

  /**
   * 开启 选项
   */
  select_node_click() {
    this.open_focusDisplay();
  }

  /**
   * 焦点元素 空白处 点击 取消 当前 操作
   * @param {MouseEvent} event
   */
  focusDisplay_white_space_self_click(event) {
    if (!event_check_func.cur_event(event).is_itself().checked_result) {
      return;
    }

    this.close_focusDisplay();
  }
}
